package com.sy.mall.order.web;

import com.alipay.api.AlipayApiException;
import com.sy.mall.order.config.AlipayTemplate;
import com.sy.mall.order.service.OrderService;
import com.sy.mall.order.vo.PayVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
//import com.lly835.bestpay.config.WxPayConfig;
//import com.lly835.bestpay.model.PayRequest;
//import com.lly835.bestpay.model.PayResponse;
//import com.lly835.bestpay.service.BestPayService;
//import com.xunqi.gulimall.order.config.AlipayTemplate;
//import com.xunqi.gulimall.order.entity.OrderEntity;
//import com.xunqi.gulimall.order.service.OrderService;
//import com.xunqi.gulimall.order.vo.PayVo;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//
//import static com.lly835.bestpay.enums.BestPayTypeEnum.WXPAY_NATIVE;



@Slf4j
@Controller
public class PayWebController {

    @Autowired
    private AlipayTemplate alipayTemplate;

    @Autowired
    private OrderService orderService;
//
//    @Autowired
//    private BestPayService bestPayService;
//

    /**
     * 用户下单:支付宝支付
     * 1、让支付页让浏览器展示
     * 2、支付成功以后，跳转到用户的订单列表页
     * @param orderSn
     * @return
     * @throws AlipayApiException
     */
    @ResponseBody
    @GetMapping(value = "/aliPayOrder",produces = "text/html")
    public String aliPayOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo);
        System.out.println(pay);
        // pay直接就是一个html页面数据 直接返回即可
        return pay;
    }


}
